﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Xml.Linq;

public partial class admintractor_admin : System.Web.UI.MasterPage
{
    
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            UsersEntities user = (UsersEntities)Session["user"];
            if (user == null)
            {
                Response.Redirect("Login.aspx");
            }
        }
    }

    public UsersEntities getUser()
    {
        UsersEntities user = (UsersEntities)Session["user"];
        return user;
    }
    public string viewRole(int id)
    {
        string tmp = "";
        RoleBusiness role = new RoleBusiness();
        ArrayList items = role.getRole();
        RoleEntities item = null;
        for (int i = 0; i < items.Count; i++)
        {
            item = (RoleEntities)items[i];
            if (item._id == id)
            {
                tmp = item._name;
                break;
            }
        }
        return tmp;
    }

    public void loadmenu()
    {
        UsersEntities use = (UsersEntities)Session["user"];
        use._roleID = 1;
        if (use != null)
        {
            int role_id = use._roleID;
            int l = Option.menu.Length / 3;
            if (role_id == 1)//admin
            {
                for (int i = 0; i < l; i++)
                {
                    Response.Write("<tr><td><a href=\"" + Option.menu[i, 1].ToString() + "\">" + Option.menu[i, 2].ToString());
                    Response.Write("</a></td></tr>");
                }
            }
            else
            {

            }
        }
        else { Response.Redirect("Login.aspx"); }
    }
    protected void but_logout_Click(object sender, EventArgs e)
    {
        Session["user"] = null;
        Response.Redirect("Login.aspx");
    }
}
